#include <vcl.h>
#pragma hdrstop
#pragma package(smart_init)

#include "UserBridge.h"

TUserBridge :: TUserBridge( TDatabase * database)
{
   qryGetUser = new TQuery( NULL);
   qryGetUser->DatabaseName = database->DatabaseName;
   qryGetUser->SQL->Add("SELECT * FROM USERS WHERE USERNAME = :prmUserName");     
}

TUserBridge :: ~TUserBridge()
{
   delete qryGetUser;
}

TUser* TUserBridge :: GetUser(AnsiString name)
{
    qryGetUser->ParamByName("prmUserName")->AsString = name;

    qryGetUser->Open();

    try
    {
       qryGetUser->First();

       if (qryGetUser->Eof)
          return NULL;

       TUser* user = new TUser();

       user->name     = name;
       user->password = qryGetUser->FieldByName("PASSWORD")->AsString;
       user->type     = (UserType)qryGetUser->FieldByName("TYPE")->AsInteger;

       return user;
   }
   __finally
   {
      qryGetUser->Close();
   }

   return NULL;
}
 